#ifndef IMAGE_PROC_H
#define IMAGE_PROC_H

#define GRAY_LEVELS 256 // 图像灰度级数
#define AVERAGE_PUPIL_RADIUS 70/4 // 预估瞳孔平均半径
#define AVERAGE_IRIS_RADIUS 150/4 // 预估虹膜平均半径
#define AVERAGE_IRIS_WIDTH 40 // 虹膜宽度，归一化分辨率

#define PICTURE_ERROR   -1  // 图片无效，没拍到虹膜信息
#define OUT_OF_MEMORY   -10 // 内存不足

typedef struct _circle {
    int x; /* 圆心坐标 */
    int y;
    int radius; // 半径
    int intensity; // 强度
    struct _circle *next;
} coordinates_circle;

// 中值滤波，3*3
extern int median_filter(unsigned char *src, unsigned char *dest, int width, int height);

// 均值滤波，3*3
extern void average_filter(unsigned char *src, unsigned char *dest, int width, int height);

// 高斯滤波，5*5，sigma一般取1.4。sigma越大，则中心像素的权重越低，图像越模糊
extern void gaussian_filter(unsigned char *src, unsigned char *dest, int width, int height, double sigma);

// 二值化
extern void binaryzation(unsigned char *src, unsigned char *dest, int width, int height, int bin_threshold);

// 二值图像反色处理
extern void bin_img_reverse(unsigned char *src, unsigned char *dest, int width, int height);

// 腐蚀
extern void erosion(unsigned char *src, unsigned char *dest, int width, int height);

// 膨胀
extern void dilation(unsigned char *src, unsigned char *dest, int width, int height);

// 开运算
extern void open_operation(unsigned char *src, unsigned char *dest, int width, int height);

// 闭运算
extern void close_operation(unsigned char *src, unsigned char *dest, int width, int height);

// 与运算
extern void and_operation(unsigned char *src, unsigned char *mask, unsigned char *dest, int width, int height);

// 或运算
extern void or_operation(unsigned char *src, unsigned char *mask, unsigned char *dest, int width, int height);

// 增强对比度，直方图均衡法
extern void increasing_contrast(unsigned char *src, unsigned char *dest, int width, int height);

// 边缘检测，基于sobel算子
extern void sobel_edge_detection(unsigned char *src, unsigned char *dest, int width, int height, int edge_threshold);

// 边缘检测，基于canny算法
extern void canny_edge_detection(unsigned char *src, unsigned char *dest, int width, int height, int edge_threshold);

// 缩小图像，长宽均为原来的一半
extern void shrunk_half_image(unsigned char *src, unsigned char *dest, int width, int height);

// 缩小图像，长宽均为原来的1/4
extern void shrunk_two_times_image(unsigned char *src, unsigned char *dest, int width, int height);

// 去掉图像中瞳孔以及距离瞳孔较远的部分
extern int remove_pupil(unsigned char *src, int width, int height, coordinates_circle *pupil, int iris_radius);

// 笛卡尔坐标到极坐标变换
extern void to_polar_coordinates(unsigned char *cartesian, int width, int height, unsigned char *polar, int radius, coordinates_circle *pole);

#endif // IMAGE_PROC_H
